<?php
	ini_set('error_reporting', e_notice);
    include_once "inc_function.php";
    include_once '../../function/class_tabel_paging.php';

?>
<body>

<fieldset class="list_employee">
   <legend> Dashboard List Employee</legend>
   <form action method='get' id=form_search>
   <div>Search : <input type='text' name='search' class='text_search' placeholder='search...' /></div>
<?php 
	if(isset($_REQUEST['auto']) && $_REQUEST['auto'] == true){
		echo "<input type='hidden' name='auto' value='true'>";
	}
?>
   </form>
<?php
	$current_page = 1;
	if(isset($_GET['page'])){
		$current_page = $_GET['page'];
	}
	
	$page_per_row1 = (isset($_REQUEST['auto']) && $_REQUEST['auto'] == true)?5:10;
	$start_myrow = ($current_page-1) * $page_per_row1 + 1;
	$end_row = $current_page * $page_per_row1;
	
	$sql_count = "SELECT COUNT(*) AS num_rows FROM M_EMPLOYEE where employee_id > 0 order by employee_id asc";
	
	if(isset($_REQUEST['auto']) && $_REQUEST['auto'] == true){
		$hidden = 'hidden';
		$headerValue = array(
			'OTHER' => array(
				'ID' => 'EMPLOYEE_ID',
				'NAME' => 'EMPLOYEE_NAME',
				'JOB_ID' => 'JOB_TITLE_ID'		
			),				
			'TABLE' => array(
				'EMPLOYEE NAME' => 'EMPLOYEE_NAME',
				'JOB TITLE' => 'JOB_TITLE_NAME',
				'MAIN COMPANY' => 'MAIN_COMPANY_NAME',
				'DIVISION NAME' => 'DIVISION_NAME',
			 )		
		);
	
		$sql1 = array(
			'sql_result' => "BEGIN PKG_MASTER.sp_get_employee_by_name(:str_employee_name,:int_start_row,:int_end_row,:cursor);END;",
			'condition' => array(
				':int_start_row' => $start_myrow,
				':int_end_row' => $end_row,
				':str_employee_name' => $search,
				':cursor' => ''	
			)
		);
		
		$function_cek_value = "
			<script>
				function cekValue(id,nama,job){
					window.parent.window.lookup_data(id,nama,job);
					self.parent.tb_remove();
				}
			</script>
		";
		echo $function_cek_value;
	}else{
		$headerValue = array(
			'OTHER' => array('ID' => 'EMPLOYEE_ID'),				
			'TABLE' => array(
				'EMPLOYEE NAME' => 'EMPLOYEE_NAME',
				'JOB TITLE' => 'JOB_TITLE_NAME',
				'MAIN COMPANY' => 'MAIN_COMPANY_NAME',
				'JOIN DATE' => 'JOIN_DATE',
				'SUPERIOR NAME' => 'SUPERIOR_NAME',
				'DIVISION NAME' => 'DIVISION_NAME',
				'STATUS' => 'STATUS_NAME'	
			 )		
		);
	
		$sql1 = array(
			'sql_result' => "BEGIN PKG_MASTER.sp_get_employee_by_name(:str_employee_name,:int_start_row,:int_end_row,:cursor);END;",
			'condition' => array(
				':int_start_row' => $start_myrow,
				':int_end_row' => $end_row,
				':str_employee_name' => $search,
				':cursor' => ''	
			)
		);
		$hidden = '';	
	}
	
	
	$search = (isset($_REQUEST['search'])) ?$_REQUEST['search']:''; 
	
	$form = AJAX_PATH."form_employee.php";
	$paging = new tabel_paging($con,$sql_count,$page_per_row1,$sql1,$headerValue);
    $total_rows = $paging->count_rows($con,$sql_count);
    $total_mypages = $paging->total_pages($total_rows, $page_per_row1);
    echo $paging->paged_result($con,$start_myrow,$page_per_row1,$sql1,$headerValue,$form);
?>
<div class="left">
<a href="http://<?= ABSPATH;?>pages/main/form_employee.php" class="button left <?= $hidden; ?>"> Create New </a>
<span class="right"><?php  echo $paging->draw_pager(AJAX_PATH."list_employee.php", $total_mypages, $current_page);?></span>
</div>
</fieldset>
</body>
